package win.zxshuo.www.service;

import org.apache.juli.logging.Log;
import org.apache.juli.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import win.zxshuo.www.model.BookModel;
import win.zxshuo.www.model.ChapterModelMongoDB;
import win.zxshuo.www.repository.ChapterMongoRepository;

import java.util.Date;
import java.util.List;

/**
 * MongoDB 相关的章节操作
 */
@Service
public class ChapterMongoService extends BaseService {


    @Autowired
    ChapterMongoRepository chapterMongoRepository;







//    /**
//     * 给书记添加章节
//     * @param bookModel
//     * @param chapterModelMongoDB
//     */
//    public void addNewChapterForBook(BookModel bookModel,ChapterModelMongoDB chapterModelMongoDB){
//        ChapterModelMongoDB chapterModelMongoDB1 = chapterMongoRepository.findByBookIdAndTitle(bookModel.getId(),chapterModelMongoDB.getTitle());
//        if (chapterModelMongoDB1 != null){
//            return;
//        }
//
//    }


    public void addNewChapterForBook(BookModel bookModel,List<ChapterModelMongoDB> chapterModelMongoDBS){
        for (ChapterModelMongoDB chapterModelMongoDB:chapterModelMongoDBS){
            chapterModelMongoDB.setBookId(bookModel.getId());
            chapterModelMongoDB.setCreateDate(new Date());
            chapterModelMongoDB.setModifyDate(new Date());
            chapterModelMongoDB.setSpiderStatus("0");
            chapterMongoRepository.save(chapterModelMongoDB);


        }
    }










}
